package alo;

/**
 * 选择排序, 每次选择最小或者最大的进行排序
 */
public class L_SelectSort {
    public static void main(String[] args) {
        double[] arr = {2.0, 2.1, 9, 5.02, 6, 3.04, 8, 4, 0.3, 5, 3.22, 6.2};
        sort(arr);
        for (double v : arr) {
            System.out.print(" " + v);
        }
    }

    private static void sort(double[] data) {
        for (int i = 0; i < data.length - 1; i++) {
            int tmp = i;
            for (int j = i + 1; j < data.length; j++) {
                if (data[tmp] > data[j]) tmp = j;//找到最小值的那个值的下标
            }
            if (tmp != i) {
                double temp = data[i];
                data[i] = data[tmp];
                data[tmp] = temp;
            }
        }
    }
}
